//
//  ViewController.m
//  homework
//
//  Created by dllo on 16/6/12.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@property (nonatomic, strong) UIView *backView;

@property (nonatomic, strong) NSArray *array;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    [self createRainBow];
}

-(void)createBack
{
    self.backView = [[UIImageView alloc]initWithFrame:self.view.frame];
    
    self.backView.backgroundColor = [UIColor blackColor];
    
    [self.view addSubview:self.backView];
}

-(void)createRainBow
{
    self.array = [NSArray arrayWithObjects:[UIColor redColor] , [UIColor grayColor], [UIColor yellowColor], [UIColor blueColor], [UIColor purpleColor], [UIColor brownColor], [UIColor greenColor], nil];
    
    for (int i = 0; i < 7; i++) {
        self.backView = [[UIView alloc]initWithFrame:CGRectMake(i * 30 + 30, i * 30 + 30, 375 - 60 * i, 375 - 60 * i)];
        
        self.backView.backgroundColor = self.array[i];
        
        self.backView.tag = i;
        
        [self.view addSubview:self.backView];
        
        
    }
    
    [NSTimer scheduledTimerWithTimeInterval:0.3 target:self selector:@selector(time) userInfo:nil repeats:YES];
    
}

-(void)time
{
//    for (int i = 0; i < 7; i++) {
//        if (i == 0 ) {
//            [self.view viewWithTag:6].backgroundColor = [self.view viewWithTag:0].backgroundColor;
//        } else {
//            [self.view viewWithTag:i - 1].backgroundColor = [self.view viewWithTag:i].backgroundColor;
//        }
//    }
    
    for (UIView *view in self.view.subviews) {
        NSInteger index = [self.array indexOfObject:view.backgroundColor];
        
        view.backgroundColor = [self.array objectAtIndex:(index + 1) % 7];
    }
    
}



@end
